package com.cblz.bd.database.spring.boot.starter.configure;

import com.cblz.bd.common.core.utils.DateUtil;
import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;

public class P6spySqlFormatConfigure implements MessageFormattingStrategy {

    @Override
    public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
        return StringUtils.isNotBlank(sql) ? "   打印时间：" + DateUtil.formatFullTime(LocalDateTime.now(), DateUtil.FULL_TIME_SPLIT_PATTERN) + StringUtils.LF + "   耗时 " + elapsed + "ms" + StringUtils.LF + "   SQL 语句：" + sql.replaceAll("[\\s]+", StringUtils.SPACE) + ";" + StringUtils.LF : StringUtils.EMPTY;
    }
}

